package com.example.chatroom.controller;

import com.example.chatroom.entity.User;
import com.example.chatroom.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

@Controller
public class UserLoginController {
//    String resource;
//    InputStream inputStream ;
//    SqlSessionFactory sqlSessionFactory;
    @Resource
    private UserMapper userMapper;

    public UserLoginController() throws IOException {
//        resource = "com/example/chatroom/mapper/UserMapper.xml";
//        inputStream = Resources.getResourceAsStream(resource);
//        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }

    @RequestMapping(value = "/user/login" ,method = RequestMethod.POST)
    @ResponseBody
    public String login(@RequestParam("username") String username ,
                        @RequestParam("password")String password){

        List<User> user=userMapper.queryAllUser();
//        User user=userMapper.queryuserbyname(username);
        System.out.println("nihao" + username + password);
//        if (username.equals(user.getUsername())&&password.equals(user.getuserpwd())){
//            return "登录成功";
//        }
//        else{
//            return "登录失败";
//        }
        return "login successfully!";
    }
}
